package cz.cvut.fel.y36pda.hs.masekji4.jirina.screens.camera;

import cz.cvut.fel.y36pda.hs.masekji4.jirina.screens.loading.LoadingScreen;
import cz.cvut.fel.y36pda.hs.masekji4.jirina.screens.unlocking.UnlockingScreen;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.container.MainScreen;

/**
 * Třída <code>CameraScreen</code> reprezentuje obrazovku zobrazující aktuální
 * záběr z bezpečnostní kamery.
 *
 * @author masekji4@fel.cvut.cz
 */
public class CameraScreen extends MainScreen {
    public Bitmap screenshot = Bitmap.getBitmapResource("screenshot.png");
    public Bitmap menu       = Bitmap.getBitmapResource("menu.png");

    private MenuItem refesh = new MenuItem("Aktualizovat záběr", 110, 10) {
        public void run() {
            UiApplication.getUiApplication().pushModalScreen(new LoadingScreen());
        }
    };

    private MenuItem unlock = new MenuItem("Odemknout dveře", 110, 10) {
        public void run() {
            UiApplication.getUiApplication().pushModalScreen(new UnlockingScreen());
        }
    };

    private MenuItem close = new MenuItem("Zavřít", 110, 10) {
        public void run() {
            System.exit(0);
        }
    };

    /**
     * Vytvoří instanci třídy <code>CameraScreen</code>.
     */
    public CameraScreen() {
        super(Manager.NO_VERTICAL_SCROLLBAR | Manager.NO_VERTICAL_SCROLL);

        addKeyListener(new CameraScreenListener(this));
    }

    /**
     * Called from onMenu to populate the menu.
     * If you override this function, you must call super.makeMenu(menu) so that
     * the MainScreen's items are added to the menu.
     *
     * @param menu          Menu to which items should be added.
     * @param instance      The instance of the desired menu. If your screen
     *                      supports only one menu, this may be ignored. By
     *                      default, it is 0.
     */
    protected void makeMenu(Menu menu, int instance) {
        menu.add(unlock);
        menu.add(refesh);
        menu.add(close);
    }

    /**
     * Vykreslí na display telefonu obsah obrazovky.
     *
     * @param graphics objekt třídy <code>Graphics</code>
     */
    protected void paint(Graphics graphics) {
        graphics.setColor(0x0000647d);
        graphics.drawRect(0, 0, 320, 240);
        graphics.fillRect(0, 0, 320, 240);
        graphics.drawBitmap(0, 0, 320, 320, screenshot, 0, 0);
        graphics.drawBitmap(0, 0, 320, 320, menu, 0, 0);
    }
}